package net.hailxenu.stats;

import java.util.Calendar;
import org.bukkit.entity.Player;

public class PlayerData
{
    public Integer JOIN = 0;
    public Integer QUIT = 0;
    public Integer STEPS = 0;
    public Integer KILLS = 0;
    public Integer DEATH = 0;
    public Integer BLOCKS_PLACED = 0;
    public Integer BLOCKS_DESTROYED = 0;
    public Integer ONLINE = 1;

    public long ONLINE_TIME_START = getTime();
    public long ONLINE_TIME_END = 0l;
    public long ONLINE_TIME_FINAL = 0l;
    public long ONLINE_SECONDS = 0l;

    public Integer qJOIN = 0;
    public Integer qQUIT = 0;
    public Integer qSTEPS = 0;
    public Integer qKILLS = 0;
    public Integer qDEATH = 0;
    public Integer qBLOCKS_PLACED = 0;
    public Integer qBLOCKS_DESTROYED = 0;

    public String playerName;

    public PlayerData(String playerName)
    {
        this.playerName = playerName;
    }

    public void setStartTime()
    {
        ONLINE_TIME_END = 0l;
        ONLINE_TIME_START = getTime();
    }

    public long getTime()
    {
        return (System.currentTimeMillis()) / 1000;
    }

    public void setEndTime()
    {
        ONLINE_TIME_END = getTime();
        ONLINE_SECONDS += ONLINE_TIME_END - ONLINE_TIME_START;
        ONLINE_TIME_START = 0l;
        ONLINE_TIME_END = 0l;

        System.out.println(playerName + " was online for " + (ONLINE_TIME_END - ONLINE_TIME_START) + " seconds.");
    }

    public void setZero()
    {
        qJOIN = 0;
        qQUIT = 0;
        qSTEPS = 0;
        qKILLS = 0;
        qDEATH = 0;
        qBLOCKS_PLACED = 0;
        qBLOCKS_DESTROYED = 0;
    }

    public String getName()
    {
        return this.playerName;
    }

    public long getOnlineTime()
    {
        if(ONLINE_TIME_START > 0l)
        {
            ONLINE_TIME_END = getTime();
            ONLINE_SECONDS += ONLINE_TIME_END - ONLINE_TIME_START;

            ONLINE_TIME_START = getTime();
            ONLINE_TIME_END = 0l;
        }
        return ONLINE_SECONDS;
    }

    public long resetOnlineTime()
    {
        long x = getOnlineTime();
        ONLINE_SECONDS = 0;
        return x;
    }

    public boolean doClearIfPossible()
    {
        if(ONLINE == 0)
        {
            if(qJOIN + qQUIT + qSTEPS + qDEATH + qBLOCKS_PLACED + qBLOCKS_DESTROYED + qKILLS + qSTEPS + ONLINE_TIME_FINAL == 0)
            {
                return true;
            }
        }
        return false;
    }

    public String getOutput()
    {
        return "update:" + playerName + ":" + ONLINE + ":" + qJOIN + ":" + qQUIT + ":" + qSTEPS + ":" + qDEATH + ":" + qBLOCKS_PLACED + ":" + qBLOCKS_DESTROYED + ":" + resetOnlineTime();
    }
}